<template>
    <chat-notification 
        :visible="notification.visible"
        :sender="notification.sender"
        :content="notification.content"
        :avatar="notification.avatar"
        @click="onNotificationClick"
    />
</template>

<script>
import { mapState, mapActions } from 'vuex';
import ChatNotification from '@/components/chat-notification/chat-notification.vue';

export default {
    name: 'GlobalNotification',
    components: {
        ChatNotification
    },
    computed: {
        ...mapState('notification', ['notification'])
    },
    methods: {
        ...mapActions('notification', ['hideNotification']),
        onNotificationClick() {
            try {
                // 跳转到对应的聊天页面（使用发送者ID）
                const senderId = this.notification.senderId || 1;
                uni.navigateTo({
                    url: `/pages/consultation/chat?id=${senderId}`
                });
                // 隐藏通知
                this.hideNotification();
            } catch (error) {
                console.error('处理通知点击出错:', error);
            }
        }
    }
}
</script> 